<code>
    <style type="text/css" title="currentStyle">
        @import "../css/ui-lightness/jquery-ui-1.7.2.custom.css";
        @import "../css/table/css/demo_table_jui.css";
        @import "../css/jquery.alerts.css";
        @import "../css/ui.multiselect.css";
        /*  @import "../css/layout.css";*/

    </style>
    <script type="text/javascript" language="javascript" src="../js/jquery-1.3.2.js"></script>
    <script type="text/javascript" language="javascript" src="../js/jquery.dataTables.js"></script>
    <script type="text/javascript" language="javascript" src="../js/jquery-ui-1.7.2.custom.min.js"></script>
    <script src="../js/jquery.alerts.js" type="text/javascript"></script>
    <script src="../js/ui.multiselect.js" type="text/javascript"></script>

    <script type="text/javascript" charset="utf-8">
        $(document).ready(function() {
            var semester;
            $("#studentInfo").hide();
            $("#groupSelectionTable").hide();
            $("#aceptInfo").click(function(){
                var studentKey=$("#studentKey").val();
                $.post("getStudentInfoJSON.do",{id:studentKey},function(result){
                    if(result.msg=="success"){
                        $("#studentName").val(result.name);
                        $("#lastName1").val(result.lastName1);
                        $("#lastName2").val(result.lastName2);
                        $("#birth").val(result.birthday);
                        $("#tel").val(result.tel);
                        $("#dir").val(result.dir);
                        $("#studentInfo").slideDown("fast");
                    }else{
                        jAlert(result.msg, "Error");
                        $("#studentInfo").slideUp("fast")
                        $("#groupSelectionTable").slideUp("fast");
                    }
                }, "json");
            });

            $("#curriculumListBox").change(function(){
                var id=$("#curriculumListBox").val();
                $("#groupSelectionTable").slideUp("fast");
                var options="";
                if(id=="0"){
                    options="";
                    $("select#semesterBox").html(options);
                }else{
                    $.getJSON("../adminMajor/getCurriculumSemester.do", {id:id}, function(response){
                        semester=response.key;
                        var options="";
                        if($("input[name='enrollType']:checked").val()=="1"){
                            //  $("#semesterBox").hide();
                            options='<option value="1">1</option>';
                        }else{
                            for(i=0; i<semester; i++){
                                options =options+"<option value=\""+(i+1)+"\">"+(i+1)+"</option>";
                            }
                        }
                        $("select#semesterBox").html(options);

                    });
                }

            });

            $("input[name='enrollType']").change(function(){
                var options="";
                $("#groupSelectionTable").slideUp("fast");
                if($("input[name='enrollType']:checked").val()=="1"){
                    options='<option value="1">1</option>';
                }else{
                    for(i=0; i<semester; i++){
                        options =options+"<option value=\""+(i+1)+"\">"+(i+1)+"</option>";
                    }
                }
                $("select#semesterBox").html(options);
            });

            $("#getAvailableGroup").click(function(){
                var studentKey=$("#studentKey").val();
                var id_curriculum=$("#curriculumListBox").val();
                var semester=$("#semesterBox").val();

                var type=$("input[name='enrollType']:checked").val();
                var groupSelectOptions="";
                
                $.post("getAvailableGroupJSON.do",{id:studentKey,idc:id_curriculum,semester:semester,enrolType:type},function(result){
                    if(result.msg=="success"){
                     for(i=0;i<result.group.length;i++){
                         groupSelectOptions=groupSelectOptions
                        +'<option value="'+result.group[i].groupName+'">'
                        +result.group[i].subjectName
                        +'---'
                        +result.group[i].professorName
                        +'</option>';                      
                    }
                        $("#groupSelectionTable").slideDown("fast");
                        $("select#groups").html(groupSelectOptions);
                        $(".groupSelectionBox").multiselect();
                        
                        
                        $(".groupSelectionBox").focus();
                }else{
                    jAlert(result.msg, "Error");
                }
                      
                }, "json");
                  });

                   
               $("#doEnroll").click(function(){
                     var theForm=$("#enrollForm").serialize();
                     $.post("doEnrollment.do", theForm, function(response){
                        if(response=="success"){
                            jAlert("Se ha inscrito correctamente", "Inscripcion")
                        }else{
                             jAlert(response, "Error");
                        }

                     }, "html");
                    });

           
            
            function stopEnterKey(evt)
            {
             var evt=(evt)?evt:((event)?event:null);
             var node=(evt.target)?evt.target:((evt.srcElement)?evt.srcElement:null);
             if((evt.keyCode == 13) && (node.type=="text")) {return false;}
            }
            document.onkeypress = stopEnterKey; //Invoking this on key press

        });
    </script>

</code>

<%@ taglib uri="http://struts.apache.org/tags-bean" prefix="bean" %>
<%@ taglib uri="http://struts.apache.org/tags-html" prefix="html" %>
<%@ taglib uri="http://struts.apache.org/tags-logic" prefix="logic" %>

<html:form action="/enrollment/doEnrollment" styleId="enrollForm">
    <table cellpadding="0" cellspacing="0" border="0" id="studentKeyTable" class="fields">
        <tr>
            <td>
                <bean:message key="label.student.key"/>:
            </td>
            <td>
                <html:text property="studentKey" styleId="studentKey"/> <html:link href="#" styleId="aceptInfo"><bean:message key="label.button.acept"/></html:link>
            </td>
        </tr>
    </table>
    <hr>
    <table cellpadding="0" cellspacing="0" border="0" id="studentInfo" class="fields">
        <tr>
            <td>
                <bean:message key="label.student.state"/>:
            </td>
            <td>
                <input type="text" disabled="true" value="yyyyyyyy" Id="type" />
            </td>
        </tr>
        <tr>
            <td>
                <bean:message key="label.student.name"/>:
            </td>
            <td>
                <input type="text" disabled="true" value="nombre" Id="studentName"/>
            </td>

            <td>

            </td>
            <td>
                <input type="text" disabled="true" value="ape1" Id="lastName1"/>
            </td>
            <td>
                <input type="text" disabled="true" value="ape2" Id="lastName2"/>
            </td>
        </tr>
        <tr>
            <td>
                <bean:message key="label.student.birthday"/>:
            </td>
            <td>
                <input type="text" disabled="true" value="aaaa/mm/dd" Id="birth"/>
            </td>
            <td width="30"></td>
            <td>
                <bean:message key="label.student.tel"/>:
            </td>
            <td>
                <input type="text" disabled="true" value="xxx-xxxxxx" Id="tel"/>
            </td>
        </tr>
        <tr>
            <td>
                <bean:message key="label.student.dir"/>:
            </td>
            <td colspan="4">
                <input type="text" disabled="true" value="xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" Id="dir" size="80"/>
            </td>
        </tr>
        <tr >
            <td colspan="6" ><hr></td>
        </tr>
        <tr>
            <td>
                <bean:message key="label.curriculum.curriculumName"/>:
            </td>
            <td><html:select property="ID_Curriculum" styleId="curriculumListBox" >
                    <html:option value="0">--Seleccion un plan de estudio--</html:option>
                    <html:options collection="curriculumList" labelProperty="curriculumName" property="ID_Curriculum" styleClass="ID_Curriculum" />
                </html:select>
            </td>
            <td colspan="2" align="right">
                <bean:message key="label.enrollment.semesterToEnroll"/>:
            </td>
            <td><html:select property="semester" styleId="semesterBox" >
                </html:select>
            </td>

        </tr>
        <tr>
            <td>
                <bean:message key="label.enrollment.enrollType"/>:
            </td>
            <td>
                <bean:message key="label.enrollment.firstEnroll"/>: <input type="radio" name="enrollType" value="1" checked="true"/>
            </td>
        </tr>
        <tr>
            <td></td>
            <td>
                <bean:message key="label.enrollment.reEnrollment"/>:&thinsp; <input type="radio" name="enrollType" value="2"/>
            </td>
            <td colspan="2" align="right">
                <a href="#" id="getAvailableGroup"><bean:message key="label.enrollment.getGroupAvailable"/></a>
            </td>

        </tr>
        <tr>
            <td></td>
            <td>
                <bean:message key="label.enrollment.relalidateEnrol"/>:&thinsp;&thinsp;&thinsp;  <input type="radio" name="enrollType" value="3"/>
            </td>

        </tr>
    </table>

    <hr>

    <table id="groupSelectionTable"  >
        <tr>
            <td>
                <select name="selectedGroup[]" multiple="multiple" class="groupSelectionBox" id="groups" > </select>
            </td>
        </tr>
        <tr>
            <td>
                <center><html:link href="#" styleId="doEnroll">Inscribir</html:link></center>
        </td>
    </tr>
    </table>

</html:form>
